package com.huike.web.controller.system;

import com.huike.clues.service.MpNoticeService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.entity.MPSysNotice;
import com.huike.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Description TODO
 * @Author guan
 * @Date 2023-08-30 11:05
 */
@RestController
@RequestMapping("/system/notice")
@Api(tags = "通知公告相关接口")
@Slf4j
public class MpNoticeController extends BaseController {

    @Resource
    private MpNoticeService mpNoticeService;


    @ApiOperation("获取系统提醒分页列表")
    @GetMapping("/pagelist/{status}")
    public TableDataInfo pagelist(@PathVariable String status){
        log.info("获取系统提醒分页列表:{}",status);

        startPage();

        List<MPSysNotice> list = mpNoticeService.selectNoticeList(SecurityUtils.getUserId(),status);
        return getDataTable(list);
     }


    @ApiOperation("获取系统提醒下拉列表")
    @GetMapping("/list/{status}")
    private AjaxResult<List<MPSysNotice>> noticeList(@PathVariable String status){
        log.info("获取系统提醒下拉列表:{}",status);

        List<MPSysNotice> mpSysNoticeList = mpNoticeService.getListStatus(status);
        return AjaxResult.success(mpSysNoticeList);
    }

    @ApiOperation("获取详情信息接口")
    @GetMapping("/{noticeId}")
    public AjaxResult<MPSysNotice> getMsgByNoticeId(@PathVariable Integer noticeId){
        log.info("获取详情信息:{}",noticeId);

        MPSysNotice mpSysNotice = mpNoticeService.getNoticeId(noticeId);
        return AjaxResult.success(mpSysNotice);
    }

    @ApiOperation("未读变已读")
    @PutMapping("/{noticeId}")
    public AjaxResult update(@RequestBody Integer noticeId){
        log.info("未读变已读:{}",noticeId);

        mpNoticeService.updateNoticeId(noticeId);
        return success();
    }
}
